package com.macro.mall.controller;

import com.github.pagehelper.PageHelper;
import com.macro.mall.annotationUtil.CurrentUserName;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.StoreStatisticsParam;
import com.macro.mall.dto.UmsAdminDTO;
import com.macro.mall.model.CheckStorageVo;
import com.macro.mall.model.StoreStatisticsResult;
import com.macro.mall.model.UmsAdmin;
import com.macro.mall.service.IndexStatisticsService;
import com.macro.mall.service.UmsAdminService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * 首页统计Controller
 * create by 孙晓亮 on 2020年9月16日
 */
@Controller
@ResponseBody
@RequestMapping("/statistics")
public class IndexStatisticsController {

    @Autowired
    IndexStatisticsService indexStatisticsService;

    @Autowired
    private UmsAdminService umsAdminService;





    /**
     * 查询首页待处理统计信息
     * @param currentUserName
     * @return
     */
    @ApiModelProperty("获取首页待处理统计信息")
    @RequestMapping(value = "/indexWaitStatistics",method = RequestMethod.GET)
    public CommonResult getIndexStatistics(@CurrentUserName String currentUserName){
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.getIndexStatistics(admin,umsAdmin.getAdminType());
    }

    /**
     * 查询首页商品总览统计信息
     */
    @ApiModelProperty("查询首页商品总览统计信息")
    @RequestMapping(value = "/indexProductStatistics",method = RequestMethod.GET)
    public CommonResult indexProductStatistics(@CurrentUserName String currentUserName){
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.indexProductStatistics(admin,umsAdmin.getAdminType());
    }
    /**
     * 查询用户总览统计信息
     */
    @ApiModelProperty("查询用户总览信息统计信息")
    @RequestMapping(value = "/indexMemberStatistics",method = RequestMethod.GET)
    public CommonResult indexMemberStatistics(@CurrentUserName String currentUserName){
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.indexMemberStatistics(admin,umsAdmin.getAdminType());
    }

    /**
     * 查询订单统计信息
     */
    @ApiModelProperty("查询订单统计信息")
    @RequestMapping(value = "/indexOrderStatistics",method = RequestMethod.GET)
    public CommonResult indexOrderStatistics(@CurrentUserName String currentUserName){
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.indexOrderStatistics(admin,umsAdmin.getAdminType());
    }


    /**
     * 店铺统计信息
     * @return
     */
    @ApiModelProperty("分页查询店铺统计信息")
    @RequestMapping(value = "/storeStatistics",method = RequestMethod.POST)
    public CommonResult<CommonPage<StoreStatisticsResult>> storeStatistics(@CurrentUserName String currentUserName, @RequestBody StoreStatisticsParam storeStatisticsParam){
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        CommonPage<StoreStatisticsResult> commonPage = indexStatisticsService.storeStatistics(admin, umsAdmin.getAdminType(), storeStatisticsParam);
//        CommonPage<StoreStatisticsResult> checkStorageVoListCommonPage = CommonPage.restPage(storeStatisticsResultList);
        return CommonResult.success(commonPage);
    }

    /**
     * 导出店铺统计信息
     */
    @ApiModelProperty("导出店铺统计信息")
    @RequestMapping(value = "/storeStatisticsExport",method = RequestMethod.POST)
    public CommonResult storeStatisticsExport(@CurrentUserName String currentUserName, @RequestBody StoreStatisticsParam storeStatisticsParam){
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
       // CommonPage<StoreStatisticsResult> commonPage =
//        CommonPage<StoreStatisticsResult> checkStorageVoListCommonPage = CommonPage.restPage(storeStatisticsResultList);
        return indexStatisticsService.storeStatisticsExport(admin, umsAdmin.getAdminType(), storeStatisticsParam);
    }


    /**
     * 查询用户统计折线图
     * @param currentUserName
     * @param queryWay
     * @param startDate
     * @param endDate
     * @return
     */
    @ApiModelProperty("查询用户统计折线图")
    @RequestMapping(value = "/memberLiceChart",method = RequestMethod.GET)
    public CommonResult memberLiceChart(@CurrentUserName String currentUserName, @RequestParam(required = false) Integer queryWay,
                                        @RequestParam(required = false)Date startDate,
                                        @RequestParam(required = false)Date endDate) throws ParseException {
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.memberLiceChart(admin,umsAdmin.getAdminType(),queryWay,startDate,endDate);
    }

    /**
     * 查询订单折线统计图
     * @param currentUserName
     * @param queryWay
     * @param startDate
     * @param endDate
     * @return
     */
    @ApiModelProperty("查询订单折线统计图")
    @RequestMapping(value = "orderLiceChart",method = RequestMethod.GET)
    public CommonResult orderLiceChart(@CurrentUserName String currentUserName,@RequestParam(required = false) Integer queryWay,
                                       @RequestParam(required = false)Date startDate,
                                       @RequestParam(required = false)Date endDate)throws ParseException {
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.orderLiceChart(admin,umsAdmin.getAdminType(),queryWay,startDate,endDate);
    }

    /**
     * 查询销售额折线统计图
     * @param currentUserName
     * @param queryWay
     * @param startDate
     * @param endDate
     * @return
     */
    @ApiModelProperty("查询销售额折线统计图")
    @RequestMapping(value = "salesLiceChart",method = RequestMethod.GET)
    public CommonResult salesLiceChart(@CurrentUserName String currentUserName,@RequestParam(required = false) Integer queryWay,
                                       @RequestParam(required = false)Date startDate,
                                       @RequestParam(required = false)Date endDate)throws ParseException {
        UmsAdmin umsAdmin = umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO admin = umsAdminService.getAdminDTOByUserName(currentUserName);
        return indexStatisticsService.salesLiceChart(admin,umsAdmin.getAdminType(),queryWay,startDate,endDate);
    }
}
